<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/22
 * Time: 14:43
 */
namespace app\api\controller;
use think\Db;
use think\Request;
use think\Session;
use think\Controller;
vendor('qiniu/php-sdk/autoload.php');;  //七牛入口文件引入
use Qiniu\Auth;
class Safe extends Nocommon
{
    //获取七牛TOKEN
    public function uploadToken(){
        if (Request::instance()->isPost()){
            $accessKey = config("qiniu")["accessKey"];
            $secretKey = config("qiniu")["secretKey"];
            // 初始化签权对象

            $auth = new Auth($accessKey, $secretKey);

            $bucket = config("qiniu")["bucket"];

            $token = $auth->uploadToken($bucket,null,7200);
            if ($token){
                echo json_encode(array('code'=>'200','msg'=>'请求成功','QNtoken'=>$token));
            }else{
                echo json_encode(array('code'=>'401','msg'=>'请求失败'));
            }
        }else{
            echo json_encode(array('code'=>'400','msg'=>'非法操作'));
        }
    }
}